const app = getApp()
const API = require("../../http/API")
const http = require("../../http/http")

// pages/trigg/trigg.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 大触标题数据
    tit_list: ["大触讲座", "大触专访", "热门大触"],
    // 更火class的索引
    classIndex: 0,
    Shj_list: [],
    zF_list:[],
    HoT_list:[],
    page: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getAllSj()
  },
  getAllSj() {
    http(API.jijiang, {
      page: this.data.page
    }).then(res => {
      if (this.data.page == 1) {
        this.setData({
          Shj_list: res.data.course.data
        })
      } else {
        this.setData({
          Shj_list: this.data.Shj_list.concat(res.data.course.data),
        })
      }

    })
  },
  getAllZf() {
    http(API.zhuanfang, {
      page: this.data.page
    }).then(res => {
      if (this.data.page == 1) {
        this.setData({
          zF_list: res.data.data
        })
      } else {
        this.setData({
          zF_list: this.data.zF_list.concat(res.data.data),
        })
      }

    })
  },
  getHot() {
    http(API.remen, {
      page: this.data.page
    }).then(res => {
      console.log(res.data.data);
      if (this.data.page == 1) {
        this.setData({
          HoT_list: res.data.data
        })
      } else {
        this.setData({
          HoT_list: this.data.HoT_list.concat(res.data.data),
        })
      }
    })
  },
  onReachBottom() {
    this.setData({
      page: this.data.page + 1
    })
    this.getAllSj()
    this.getAllZf()
    this.getHot()

  },
  // 时间处理
  listClick(e) {
    this.setData({
      classIndex: e.target.dataset.index
    })
    if (e.target.dataset.index == 1) {
      this.getAllZf()
    }
    if (e.target.dataset.index == 2) {
      this.getHot()
    }
  }

})